import time
from selenium.webdriver.common.by import By
from A3mall.Page.Page import Page

class Page3(Page):
    #断言2：文本断言：欢迎回来
    dy2_loc=(By.PARTIAL_LINK_TEXT,'欢迎回来，130')
    def dy2(self):
        return self.text(self.dy2_loc)

    #点击首页
    home_loc=(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def home(self):
        self.click(self.home_loc)

    #点击商品：复苏呼吸机
    goods_loc=(By.XPATH,'/html/body/div[8]/div[1]/div[2]/div[2]/ul/li[2]/div[1]/a/img')
    def goods(self):
        self.click(self.goods_loc)

    #点击加入购物车
    car_loc=(By.XPATH,'//*[@id="add-cart"]')
    def car(self):
        self.click(self.car_loc)

    #点击进入购物车
    go_car_loc=(By.XPATH,'/html/body/div[3]/div[3]/div[2]/a')
    def go_car(self):
        self.click(self.go_car_loc)

    #点击勾选商品：复苏呼吸机
    select_goods_loc=(By.XPATH,'//*[@id="cart-box"]/div[1]/table/tbody/tr[2]/td[1]/input')
    def select_goods(self):
        self.click(self.select_goods_loc)

    #点击立即结算
    buy_loc=(By.XPATH,'//*[@id="cartForm"]/div[2]/div/a[2]')
    def buy(self):
        self.click(self.buy_loc)

    #选择收货地址
    addr_loc = (By.XPATH, '//input[@id="address-36" and @name="address_id"]')
    def addr(self):
        self.click(self.addr_loc)

    # 选择支付方式
    money_loc = (By.XPATH, '//*[@id="theForm"]/div[3]/div[2]/div[1]/label/input')
    def money(self):
        self.click(self.money_loc)

    #点击下一步
    next_loc = (By.ID, 'order-button')
    def next(self):
        self.click(self.next_loc)

    #断言4：断言文本：支付成功
    dy4_loc = (By.XPATH, '/html/body/div[4]/div[3]/span')
    def dy4(self):
        return self.text(self.dy4_loc)

    #调用操作和页面元素
    def luoji_a3mall_03_car(self):
        self.luoji_a3mall_01_login()
        time.sleep(3)
        assert '欢迎回来，13051749131' == self.dy2()
        print('断言2：文本断言：欢迎回来，13051749131：',self.dy2())
        self.home()
        #滚动1500像素
        self.scroll(1500)
        self.goods()
        self.car()
        self.go_car()
        self.select_goods()
        time.sleep(2)
        self.buy()
        self.addr()
        self.money()
        self.next()
        time.sleep(3)
        assert '您的订单支付成功' == self.dy4()
        print('断言3：文本断言：您的订单支付成功：',self.dy4())

